/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Design.java
 *
 * Created on Oct 16, 2012, 8:25:51 PM
 */
package test.shanika;

import UserInterface.*;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.AbstractAction;
import javax.swing.Action;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import static com.googlecode.javacv.cpp.opencv_core.*;
import com.googlecode.javacv.cpp.opencv_core.IplImage;
import java.awt.BasicStroke;
import java.awt.Desktop;
import java.awt.Graphics2D;
import java.io.File;
import javax.imageio.ImageIO;
import javax.swing.ButtonGroup;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.Timer;
import javax.swing.UIManager;
import static com.googlecode.javacv.cpp.opencv_imgproc.*;

/**
 *
 * @author HOME
 */
public class Design1 extends javax.swing.JFrame {

    /** Creates new form Design */
    private static int saveImageNum = 0;
    private ImageIcon ic = new ImageIcon();
    private ImageIcon ic2 = new ImageIcon();
    private ImageIcon drawing = new ImageIcon();
    private static IplImage liveCam1;
    private static IplImage skin1;
    private static CvSize imSize = new CvSize(217, 187);
    private static IplImage tempIm = cvCreateImage(imSize, 8, 3);
    private static IplImage tempSkin = cvCreateImage(imSize, 8, 1);
    private static int x;
    private static int y;
    private static int kx;
    private static int ky;
    private int prevX = 0, prevY = 0;
    private static int ii = 0;
    static Timer initTimer;
    Timer timer;
    Thread thread;
    Color linecolor = Color.BLACK;
    ButtonGroup colorButton = new ButtonGroup();
    private boolean rightCamPressed = false, leftCamPressed = false;
    private boolean deviceStarted = false, clearSet = false;
    Graphics2D g;
    JFileChooser fc = null;
    File file;
    BufferedImage bf, saveImage, newImage;
    BufferedImage[] imageDb = new BufferedImage[5];
    static boolean active;

    public static boolean isThreadActive() {
        return active;
    }

    public void setX_Y(int x, int y) {
        Design1.x = x;
        Design1.y = y;
    }

    public BufferedImage getLiveCam1() {
        cvResize(liveCam1, tempIm);
        return tempIm.getBufferedImage();
    }

    public void setRight(IplImage liveCam1, IplImage skin1) {
        Design1.liveCam1 = liveCam1;
        Design1.skin1 = skin1;
    }

    public BufferedImage getSkin1() {
        cvResize(skin1, tempSkin);
        return tempSkin.getBufferedImage();
    }

    public Design1() {
        initComponents();
        colorButton.add(blackRadioButton);
        colorButton.add(blueRadioButton);
        colorButton.add(greenRadioButton);
        colorButton.add(redRadioButton);
        blackRadioButton.setSelected(true);
        jButton2.setEnabled(false);
        jButton3.setEnabled(false);
        jButton4.setEnabled(false);
        jButton5.setEnabled(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        drawingPanel = new javax.swing.JPanel();
        drawLabel = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        leftPanel = new javax.swing.JPanel();
        leftLivecamPanel = new javax.swing.JPanel();
        leftLiveCamLabel = new javax.swing.JLabel();
        leftSkinPanel = new javax.swing.JPanel();
        leftSkinLabel = new javax.swing.JLabel();
        rightPanel = new javax.swing.JPanel();
        jPanel9 = new javax.swing.JPanel();
        rightSkinLabel = new javax.swing.JLabel();
        jPanel7 = new javax.swing.JPanel();
        rightLiveCamLabel = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        jSlider1 = new javax.swing.JSlider(1,10,5);
        jPanel6 = new javax.swing.JPanel();
        blackRadioButton = new javax.swing.JRadioButton();
        redRadioButton = new javax.swing.JRadioButton();
        greenRadioButton = new javax.swing.JRadioButton();
        blueRadioButton = new javax.swing.JRadioButton();
        jToolBar1 = new javax.swing.JToolBar();
        startButton = new javax.swing.JButton();
        pauseButton = new javax.swing.JButton();
        stopButton = new javax.swing.JButton();
        cameraButton = new javax.swing.JButton();
        jToolBar2 = new javax.swing.JToolBar();
        penButton = new javax.swing.JButton();
        eraserButton = new javax.swing.JButton();
        clearScreen = new javax.swing.JButton();
        imageButton = new javax.swing.JButton();
        nextButton = new javax.swing.JButton();
        prevButton = new javax.swing.JButton();
        jToolBar3 = new javax.swing.JToolBar();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        deviceMenu1 = new javax.swing.JMenuItem();
        stopMenu = new javax.swing.JMenuItem();
        findCam = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenu3 = new javax.swing.JMenu();
        leftCamMenu = new javax.swing.JMenuItem();
        rightCamMenu = new javax.swing.JMenuItem();
        jMenu4 = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();
        powerPoint = new javax.swing.JMenuItem();
        jMenuItem7 = new javax.swing.JMenuItem();
        jMenu5 = new javax.swing.JMenu();
        jMenuItem9 = new javax.swing.JMenuItem();
        jMenuItem10 = new javax.swing.JMenuItem();
        saveImMenu = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Interactive Surface");
        setAlwaysOnTop(true);
        setBounds(new java.awt.Rectangle(0, 0, 0, 0));
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setExtendedState(MAXIMIZED_BOTH);
        setFocusTraversalPolicyProvider(true);

        drawingPanel.setBackground(new java.awt.Color(255, 255, 255));
        drawingPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true), "Screen", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12))); // NOI18N
        drawingPanel.setNextFocusableComponent(drawingPanel);
        drawingPanel.setPreferredSize(new java.awt.Dimension(800, 600));

        drawLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

        javax.swing.GroupLayout drawingPanelLayout = new javax.swing.GroupLayout(drawingPanel);
        drawingPanel.setLayout(drawingPanelLayout);
        drawingPanelLayout.setHorizontalGroup(
            drawingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(drawLabel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 807, Short.MAX_VALUE)
        );
        drawingPanelLayout.setVerticalGroup(
            drawingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(drawingPanelLayout.createSequentialGroup()
                .addComponent(drawLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 607, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(21, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true), "Display", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12))); // NOI18N

        leftPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Left Camera", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12))); // NOI18N

        leftLivecamPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Live Camera", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12))); // NOI18N
        leftLivecamPanel.setPreferredSize(new java.awt.Dimension(210, 210));

        javax.swing.GroupLayout leftLivecamPanelLayout = new javax.swing.GroupLayout(leftLivecamPanel);
        leftLivecamPanel.setLayout(leftLivecamPanelLayout);
        leftLivecamPanelLayout.setHorizontalGroup(
            leftLivecamPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(leftLivecamPanelLayout.createSequentialGroup()
                .addComponent(leftLiveCamLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)
                .addContainerGap())
        );
        leftLivecamPanelLayout.setVerticalGroup(
            leftLivecamPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(leftLiveCamLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE)
        );

        leftSkinPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Skin Image", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12))); // NOI18N
        leftSkinPanel.setPreferredSize(new java.awt.Dimension(210, 210));

        javax.swing.GroupLayout leftSkinPanelLayout = new javax.swing.GroupLayout(leftSkinPanel);
        leftSkinPanel.setLayout(leftSkinPanelLayout);
        leftSkinPanelLayout.setHorizontalGroup(
            leftSkinPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(leftSkinPanelLayout.createSequentialGroup()
                .addComponent(leftSkinLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 196, Short.MAX_VALUE)
                .addContainerGap())
        );
        leftSkinPanelLayout.setVerticalGroup(
            leftSkinPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(leftSkinLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout leftPanelLayout = new javax.swing.GroupLayout(leftPanel);
        leftPanel.setLayout(leftPanelLayout);
        leftPanelLayout.setHorizontalGroup(
            leftPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(leftPanelLayout.createSequentialGroup()
                .addComponent(leftLivecamPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 221, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(leftSkinPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 218, Short.MAX_VALUE))
        );
        leftPanelLayout.setVerticalGroup(
            leftPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, leftPanelLayout.createSequentialGroup()
                .addGroup(leftPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(leftSkinPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 207, Short.MAX_VALUE)
                    .addComponent(leftLivecamPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 207, Short.MAX_VALUE))
                .addContainerGap())
        );

        rightPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Right Camera", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12))); // NOI18N

        jPanel9.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Skin Image", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12))); // NOI18N
        jPanel9.setPreferredSize(new java.awt.Dimension(210, 210));

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addComponent(rightSkinLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(rightSkinLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 178, Short.MAX_VALUE)
        );

        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Live Camera", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12))); // NOI18N
        jPanel7.setPreferredSize(new java.awt.Dimension(210, 210));

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(rightLiveCamLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 211, Short.MAX_VALUE)
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addComponent(rightLiveCamLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 167, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout rightPanelLayout = new javax.swing.GroupLayout(rightPanel);
        rightPanel.setLayout(rightPanelLayout);
        rightPanelLayout.setHorizontalGroup(
            rightPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(rightPanelLayout.createSequentialGroup()
                .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, 223, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel9, javax.swing.GroupLayout.PREFERRED_SIZE, 218, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        rightPanelLayout.setVerticalGroup(
            rightPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel7, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 205, Short.MAX_VALUE)
            .addComponent(jPanel9, javax.swing.GroupLayout.DEFAULT_SIZE, 205, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(17, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(rightPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(leftPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(leftPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(rightPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true), "Pen", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12))); // NOI18N

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Line Width", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12))); // NOI18N
        jPanel5.setFont(new java.awt.Font("Tahoma", 0, 12));

        jSlider1.setForeground(new java.awt.Color(0, 0, 0));
        jSlider1.setMajorTickSpacing(1);
        jSlider1.setMaximum(10);
        jSlider1.setPaintLabels(true);
        jSlider1.setPaintTicks(true);
        jSlider1.setPaintTrack(true);
        jSlider1.setSnapToTicks(true);
        jSlider1.setValue(5);
        jSlider1.setAutoscrolls(true);

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jSlider1, javax.swing.GroupLayout.DEFAULT_SIZE, 232, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addComponent(jSlider1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(12, Short.MAX_VALUE))
        );

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Color", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12))); // NOI18N

        blackRadioButton.setFont(new java.awt.Font("Tahoma", 1, 12));
        blackRadioButton.setText("Black");
        blackRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                blackRadioButtonActionPerformed(evt);
            }
        });

        redRadioButton.setFont(new java.awt.Font("Tahoma", 1, 12));
        redRadioButton.setText("Red");
        redRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                redRadioButtonActionPerformed(evt);
            }
        });

        greenRadioButton.setFont(new java.awt.Font("Tahoma", 1, 12));
        greenRadioButton.setText("Green");
        greenRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                greenRadioButtonActionPerformed(evt);
            }
        });

        blueRadioButton.setFont(new java.awt.Font("Tahoma", 1, 12));
        blueRadioButton.setText("Blue");
        blueRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                blueRadioButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(blackRadioButton)
                    .addComponent(blueRadioButton))
                .addGap(36, 36, 36)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(greenRadioButton)
                    .addComponent(redRadioButton))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(blackRadioButton)
                    .addComponent(greenRadioButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(blueRadioButton)
                    .addComponent(redRadioButton)))
        );

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(36, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 76, Short.MAX_VALUE)
                    .addComponent(jPanel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        jToolBar1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jToolBar1.setOrientation(1);
        jToolBar1.setRollover(true);
        jToolBar1.setAutoscrolls(true);

        startButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/UserInterface/Play.png"))); // NOI18N
        startButton.setToolTipText("Start Device");
        startButton.setFocusable(false);
        startButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        startButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        startButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                startButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(startButton);

        pauseButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/test/shanika/player-pause.png"))); // NOI18N
        pauseButton.setFocusable(false);
        pauseButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        pauseButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        pauseButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pauseButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(pauseButton);

        stopButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/UserInterface/Stop playing.png"))); // NOI18N
        stopButton.setToolTipText("Stop Device");
        stopButton.setFocusable(false);
        stopButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        stopButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        stopButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                stopButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(stopButton);

        cameraButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/UserInterface/Camera.png"))); // NOI18N
        cameraButton.setToolTipText("Show Cameras");
        cameraButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        cameraButton.setOpaque(false);
        cameraButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        cameraButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cameraButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(cameraButton);

        jToolBar2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jToolBar2.setOrientation(1);
        jToolBar2.setRollover(true);

        penButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/UserInterface/Pen.png"))); // NOI18N
        penButton.setToolTipText("Pen");
        penButton.setFocusable(false);
        penButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        penButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        penButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                penButtonActionPerformed(evt);
            }
        });
        jToolBar2.add(penButton);

        eraserButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/UserInterface/Eraser.png"))); // NOI18N
        eraserButton.setToolTipText("Eraser");
        eraserButton.setFocusable(false);
        eraserButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        eraserButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        eraserButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                eraserButtonActionPerformed(evt);
            }
        });
        jToolBar2.add(eraserButton);

        clearScreen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/UserInterface/Clear.png"))); // NOI18N
        clearScreen.setToolTipText("Clear Screen");
        clearScreen.setFocusable(false);
        clearScreen.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        clearScreen.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        clearScreen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clearScreenActionPerformed(evt);
            }
        });
        jToolBar2.add(clearScreen);

        imageButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/UserInterface/New image.png"))); // NOI18N
        imageButton.setToolTipText("Insert Image");
        imageButton.setFocusable(false);
        imageButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        imageButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        imageButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                imageButtonActionPerformed(evt);
            }
        });
        jToolBar2.add(imageButton);

        nextButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/UserInterface/Right.png"))); // NOI18N
        nextButton.setFocusable(false);
        nextButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        nextButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        nextButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nextButtonActionPerformed(evt);
            }
        });
        jToolBar2.add(nextButton);

        prevButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/UserInterface/Left.png"))); // NOI18N
        prevButton.setFocusable(false);
        prevButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        prevButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        prevButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                prevButtonActionPerformed(evt);
            }
        });
        jToolBar2.add(prevButton);

        jToolBar3.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jToolBar3.setOrientation(1);
        jToolBar3.setRollover(true);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/UserInterface/1.png"))); // NOI18N
        jButton1.setFocusable(false);
        jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jToolBar3.add(jButton1);

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/UserInterface/14_number_blue_2.png"))); // NOI18N
        jButton2.setFocusable(false);
        jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar3.add(jButton2);

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/UserInterface/14_number_blue_3.png"))); // NOI18N
        jButton3.setFocusable(false);
        jButton3.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton3.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar3.add(jButton3);

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/UserInterface/14_number_blue_4.png"))); // NOI18N
        jButton4.setFocusable(false);
        jButton4.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton4.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar3.add(jButton4);

        jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/UserInterface/14_number_blue_5.png"))); // NOI18N
        jButton5.setFocusable(false);
        jButton5.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton5.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar3.add(jButton5);

        jMenu1.setText("Device");
        jMenu1.setFont(new java.awt.Font("Arial", 1, 12));

        deviceMenu1.setFont(new java.awt.Font("Arial", 1, 12));
        deviceMenu1.setText("Start Device");
        deviceMenu1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deviceMenu1ActionPerformed(evt);
            }
        });
        jMenu1.add(deviceMenu1);

        stopMenu.setFont(new java.awt.Font("Arial", 1, 12));
        stopMenu.setText("Stop Device");
        stopMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                stopMenuActionPerformed(evt);
            }
        });
        jMenu1.add(stopMenu);

        findCam.setText("Find Cameras");
        findCam.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                findCamActionPerformed(evt);
            }
        });
        jMenu1.add(findCam);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Stylus");
        jMenu2.setFont(new java.awt.Font("Arial", 1, 12));

        jMenuItem3.setFont(new java.awt.Font("Arial", 1, 12));
        jMenuItem3.setText("Finger");
        jMenu2.add(jMenuItem3);

        jMenuItem4.setFont(new java.awt.Font("Arial", 1, 12));
        jMenuItem4.setText("Red Stylus");
        jMenu2.add(jMenuItem4);

        jMenuBar1.add(jMenu2);

        jMenu3.setText("Display");
        jMenu3.setFont(new java.awt.Font("Arial", 1, 12));

        leftCamMenu.setFont(new java.awt.Font("Arial", 1, 12));
        leftCamMenu.setText("Start Left Camera");
        leftCamMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                leftCamMenuActionPerformed(evt);
            }
        });
        jMenu3.add(leftCamMenu);

        rightCamMenu.setFont(new java.awt.Font("Arial", 1, 12));
        rightCamMenu.setText("Start Right Camera");
        rightCamMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rightCamMenuActionPerformed(evt);
            }
        });
        jMenu3.add(rightCamMenu);

        jMenuBar1.add(jMenu3);

        jMenu4.setText("Application");
        jMenu4.setFont(new java.awt.Font("Arial", 1, 12));

        jMenuItem2.setFont(new java.awt.Font("Arial", 1, 12));
        jMenuItem2.setText("Free Hand");
        jMenu4.add(jMenuItem2);

        powerPoint.setFont(new java.awt.Font("Arial", 1, 12));
        powerPoint.setText("Power Point");
        powerPoint.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                powerPointActionPerformed(evt);
            }
        });
        jMenu4.add(powerPoint);

        jMenuItem7.setFont(new java.awt.Font("Arial", 1, 12));
        jMenuItem7.setText("Photo Viewer");
        jMenu4.add(jMenuItem7);

        jMenuBar1.add(jMenu4);

        jMenu5.setText("Tools");
        jMenu5.setFont(new java.awt.Font("Arial", 1, 12));

        jMenuItem9.setText("Eraser");
        jMenuItem9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem9ActionPerformed(evt);
            }
        });
        jMenu5.add(jMenuItem9);

        jMenuItem10.setText("Clear Screen");
        jMenu5.add(jMenuItem10);

        saveImMenu.setText("Save Images");
        saveImMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveImMenuActionPerformed(evt);
            }
        });
        jMenu5.add(saveImMenu);

        jMenuBar1.add(jMenu5);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(drawingPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 817, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jToolBar3, 0, 0, Short.MAX_VALUE)
                    .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 44, Short.MAX_VALUE)
                    .addComponent(jToolBar2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(drawingPanel, 0, 653, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(16, 16, 16)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(12, 12, 12)
                                .addComponent(jToolBar2, javax.swing.GroupLayout.PREFERRED_SIZE, 238, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jToolBar3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void blackRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_blackRadioButtonActionPerformed
        linecolor = Color.BLACK;
}//GEN-LAST:event_blackRadioButtonActionPerformed

    private void deviceMenu1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deviceMenu1ActionPerformed
        deviceStarted = true;
        deviceMenu1.setEnabled(false);
        startButton.setEnabled(false);
        Testing1 tes = new Testing1();
        thread = new Thread(tes);
        thread.start();
        timer = new Timer(15, paintTimer);
        timer.start();
    }//GEN-LAST:event_deviceMenu1ActionPerformed

    private void leftCamMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_leftCamMenuActionPerformed
        leftCamPressed = true;
    }//GEN-LAST:event_leftCamMenuActionPerformed

    private void stopMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stopMenuActionPerformed
        startButton.setEnabled(true);
        stopButton.setEnabled(false);
        deviceMenu1.setEnabled(true);
        stopMenu.setEnabled(false);
        thread.stop();
    }//GEN-LAST:event_stopMenuActionPerformed

    private void greenRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_greenRadioButtonActionPerformed
        linecolor = Color.GREEN;
    }//GEN-LAST:event_greenRadioButtonActionPerformed

    private void blueRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_blueRadioButtonActionPerformed
        linecolor = Color.BLUE;
    }//GEN-LAST:event_blueRadioButtonActionPerformed

    private void redRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_redRadioButtonActionPerformed
        linecolor = Color.RED;
    }//GEN-LAST:event_redRadioButtonActionPerformed

    private void jMenuItem9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem9ActionPerformed
        linecolor = Color.WHITE;
    }//GEN-LAST:event_jMenuItem9ActionPerformed

    private void rightCamMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rightCamMenuActionPerformed
        rightCamPressed = true;
    }//GEN-LAST:event_rightCamMenuActionPerformed

    private void cameraButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cameraButtonActionPerformed
        if (!deviceStarted) {
            JOptionPane.showMessageDialog(drawingPanel, "Please Start The Device First", "Information", 1);
        } else {
            rightCamPressed = true;
            leftCamPressed = true;
        }
    }//GEN-LAST:event_cameraButtonActionPerformed

    private void startButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startButtonActionPerformed
        active = true;
        if (deviceStarted) {
            pauseButton.setEnabled(true);
            timer.restart();
        } else {
            deviceStarted = true;
            startButton.setEnabled(false);
            saveImage = new BufferedImage(drawingPanel.getWidth(), drawingPanel.getHeight(), BufferedImage.TYPE_INT_ARGB);
            for (int i = 0; i < imageDb.length; i++) {
                imageDb[i] = new BufferedImage(drawingPanel.getWidth(), drawingPanel.getHeight(), BufferedImage.TYPE_INT_ARGB);
            }
            g = (Graphics2D) saveImage.getGraphics();
            Testing1 tes = new Testing1();
            thread = new Thread(tes);
            thread.start();
            timer = new Timer(15, paintTimer);
            timer.start();
//            initTimer = new Timer(50, initialTimer);
//            initTimer.start();
        }
    }//GEN-LAST:event_startButtonActionPerformed

    private void stopButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stopButtonActionPerformed

        if (!deviceStarted) {
            JOptionPane.showMessageDialog(drawingPanel, "Please Start The Device First", "Information", 1);
        } else {
            startButton.setEnabled(true);
            stopButton.setEnabled(false);
            deviceMenu1.setEnabled(true);
            stopMenu.setEnabled(false);
            int con = JOptionPane.showConfirmDialog(drawingPanel, "Do You Really Want To Stop The Device?", "Confirmation", JOptionPane.YES_NO_CANCEL_OPTION);

            if (con == 0) {
                active = false;
//
                //  thread.stop();
                //    Thread.currentThread().stop();
                ds.dispose();
            }
        }
    }//GEN-LAST:event_stopButtonActionPerformed

    private void eraserButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_eraserButtonActionPerformed
        linecolor = getBackground();
    }//GEN-LAST:event_eraserButtonActionPerformed

    private void penButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_penButtonActionPerformed
        blackRadioButton.setSelected(true);
        linecolor = Color.BLACK;
    }//GEN-LAST:event_penButtonActionPerformed

    private void clearScreenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearScreenActionPerformed
        saveImage = new BufferedImage(drawingPanel.getWidth(), drawingPanel.getHeight(), BufferedImage.TYPE_INT_ARGB);
    }//GEN-LAST:event_clearScreenActionPerformed

    private void imageButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_imageButtonActionPerformed
        setBackgroundImage();
    }//GEN-LAST:event_imageButtonActionPerformed

    private void powerPointActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_powerPointActionPerformed

        Desktop dt = Desktop.getDesktop();
        JFileChooser fchose = new JFileChooser();
        fchose.showOpenDialog(this);
        File f = fchose.getSelectedFile();
        try {
            dt.open(f);
        } catch (IOException ex) {
            //Logger.getLogger(Design1.class.getName()).log(Level.SEVERE, null, ex);
            System.out.println("pp openning error");
        }
    }//GEN-LAST:event_powerPointActionPerformed

    private void nextButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nextButtonActionPerformed
        imageDb[saveImageNum] = saveImage;
        System.out.println(saveImageNum);
        setImageLabel(saveImageNum, +1);
        if (saveImageNum == 4) {
            saveImageNum = -1;
        }
        saveImageNum++;
        clearSet = true;
    }//GEN-LAST:event_nextButtonActionPerformed

    private void prevButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_prevButtonActionPerformed
        imageDb[saveImageNum] = saveImage;
        setImageLabel(saveImageNum, -1);
        if (saveImageNum == 0) {
            saveImageNum = 5;
        }
        saveImageNum--;
        clearSet = true;
    }//GEN-LAST:event_prevButtonActionPerformed

    private void findCamActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_findCamActionPerformed
        // TODO add your handling code here:
        new Initialising().setVisible(true);
    }//GEN-LAST:event_findCamActionPerformed

    private void saveImMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveImMenuActionPerformed
        File fiile = null;
        int selection = JOptionPane.showConfirmDialog(drawingPanel, "Do you really want to save the images?", "Save", 1);
        if (selection == 0) {
            JFileChooser ffc = new JFileChooser();
            ffc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            int returnVal = ffc.showDialog(this, "Save");
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                fiile = ffc.getSelectedFile();
            }
            imageDb[saveImageNum] = saveImage;
            for (int i = 0; i < imageDb.length; i++) {
                try {
                    String fileNum = fiile.getAbsolutePath() + "\\Drawing_" + (i + 1) + ".jpg";
                    ImageIO.write(imageDb[i], "jpg", new java.io.File(fileNum));
                } catch (java.io.IOException e) {
                    System.out.println("Unable to save image:\n" + e);
                }
            }
        }
    }//GEN-LAST:event_saveImMenuActionPerformed

    private void pauseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pauseButtonActionPerformed
        timer.stop();
        pauseButton.setEnabled(false);
        startButton.setEnabled(true);
    }//GEN-LAST:event_pauseButtonActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        System.out.println(drawLabel.getLocationOnScreen().x);
        System.out.println(drawLabel.getLocationOnScreen().y);

    }//GEN-LAST:event_jButton1ActionPerformed
    /**
     * @param args the command line arguments
     */
    static Design1 ds;

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {

                try {
                    UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");

                } catch (Exception e) {
                    System.out.println("Nimbus isn't available");
                }
                ds = new Design1();
                ds.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JRadioButton blackRadioButton;
    private javax.swing.JRadioButton blueRadioButton;
    private javax.swing.JButton cameraButton;
    private javax.swing.JButton clearScreen;
    private javax.swing.JMenuItem deviceMenu1;
    private javax.swing.JLabel drawLabel;
    private javax.swing.JPanel drawingPanel;
    private javax.swing.JButton eraserButton;
    private javax.swing.JMenuItem findCam;
    private javax.swing.JRadioButton greenRadioButton;
    private javax.swing.JButton imageButton;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenu jMenu4;
    private javax.swing.JMenu jMenu5;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem10;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem7;
    private javax.swing.JMenuItem jMenuItem9;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JSlider jSlider1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JToolBar jToolBar2;
    private javax.swing.JToolBar jToolBar3;
    private javax.swing.JMenuItem leftCamMenu;
    private javax.swing.JLabel leftLiveCamLabel;
    private javax.swing.JPanel leftLivecamPanel;
    private javax.swing.JPanel leftPanel;
    private javax.swing.JLabel leftSkinLabel;
    private javax.swing.JPanel leftSkinPanel;
    private javax.swing.JButton nextButton;
    private javax.swing.JButton pauseButton;
    private javax.swing.JButton penButton;
    private javax.swing.JMenuItem powerPoint;
    private javax.swing.JButton prevButton;
    private javax.swing.JRadioButton redRadioButton;
    private javax.swing.JMenuItem rightCamMenu;
    private javax.swing.JLabel rightLiveCamLabel;
    private javax.swing.JPanel rightPanel;
    private javax.swing.JLabel rightSkinLabel;
    private javax.swing.JMenuItem saveImMenu;
    private javax.swing.JButton startButton;
    private javax.swing.JButton stopButton;
    private javax.swing.JMenuItem stopMenu;
    // End of variables declaration//GEN-END:variables
    Action paintTimer = new AbstractAction() {

        public void actionPerformed(ActionEvent e) {

            g = (Graphics2D) saveImage.getGraphics();
            g.setBackground(drawingPanel.getBackground());
            if (!clearSet) {

                int xx = Design1.x;
                int yy = Design1.y;

                if ((prevX == 0 && prevY == 0) || (xx == 0 && yy == 0)) {
                } else {
                    g.setColor(linecolor);
                    g.setStroke(new BasicStroke(jSlider1.getValue()));
                  g.drawLine(prevX, prevY, xx, yy);
                      //g.fillOval(xx, yy, 15, 15);
                    drawing.setImage(saveImage);
                    drawLabel.setIcon(drawing);
                    drawingPanel.repaint();
                }
                prevX = xx;
                prevY = yy;

                if (leftCamPressed) {
                    liveCamViewer(1);
                }
                if (rightCamPressed) {
                    liveCamViewer(2);
                }
            } else {
                saveImage = imageDb[saveImageNum];
                clearSet = false;
            }
        }
    };

    public void liveCamViewer(int selectedCam) {

        if (selectedCam == 1) {
            ic.setImage(getLiveCam1());
            leftLiveCamLabel.setIcon(ic);

            ic2.setImage(getSkin1());
            leftSkinLabel.setIcon(ic2);

            leftCamMenu.setText("Stop Left Camera");
            leftPanel.repaint();

        } else {
            ic.setImage(getLiveCam1());

            rightLiveCamLabel.setIcon(ic);

            ic2.setImage(getSkin1());
            rightSkinLabel.setIcon(ic2);

            rightPanel.repaint();
        }
    }

    public void setBackgroundImage() {

        if (fc == null) {
            fc = new JFileChooser();

            fc.addChoosableFileFilter(new ImageFilter());
            fc.setAcceptAllFileFilterUsed(false);
//fc.setFileFilter(new ImageFilter());
            fc.setAccessory(new ImagePreview(fc));
        }
        int returnVal = fc.showDialog(this, "Open");

        //Process the results.
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            file = fc.getSelectedFile();

        } else {
        }

        fc.setSelectedFile(null);
        try {
            bf = ImageIO.read(file);
        } catch (IOException ex) {
            Logger.getLogger(Design1.class.getName()).log(Level.SEVERE, null, ex);
        }
        saveImage = bf;
    }

    public void setImageLabel(int num, int sign) {
        switch (num + 1) {
            case 1:
                jButton1.setEnabled(false);
                if (sign == +1) {
                    jButton2.setEnabled(true);
                } else {
                    jButton5.setEnabled(true);
                }
                break;
            case 2:
                jButton2.setEnabled(false);
                if (sign == +1) {
                    jButton3.setEnabled(true);
                } else {
                    jButton1.setEnabled(true);
                }
                break;
            case 3:
                jButton3.setEnabled(false);
                if (sign == +1) {
                    jButton4.setEnabled(true);
                } else {
                    jButton2.setEnabled(true);
                }
                break;
            case 4:
                jButton4.setEnabled(false);
                if (sign == +1) {
                    jButton5.setEnabled(true);
                } else {
                    jButton3.setEnabled(true);
                }
                break;
            case 5:
                jButton5.setEnabled(false);
                if (sign == +1) {
                    jButton1.setEnabled(true);
                } else {
                    jButton4.setEnabled(true);
                }
                break;
        }
    }
    Action initialTimer = new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            try {
                BufferedImage ani = null;
                BufferedImage subAni = null;

                ani = ImageIO.read(new File((getClass().getResource("/UserInterface/board.jpg")).getPath()));

                int inity = ani.getHeight() / 10;

                subAni = ani.getSubimage(0, 0, ani.getWidth(), (ii + 1) * inity);

                drawLabel.setIcon(new javax.swing.ImageIcon(subAni));
                drawingPanel.repaint();
                Thread.sleep(500);
                if (ii == 9) {
                    Thread.sleep(1000);
                    initTimer.stop();
                    timer = new Timer(15, paintTimer);
                    timer.start();
                }
                ii++;
                ani.flush();
                subAni.flush();

            } catch (InterruptedException ex) {
                Logger.getLogger(Design1.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(Design1.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
    };
}
